package com.share.design.mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * author:caifan
 * date:2020/2/6
 */
public class ConcreteMediator implements Mediator {

    private List<Colleague> colleagueList = new ArrayList<>();

    @Override
    public void register(Colleague colleague) {
        if (!colleagueList.contains(colleague)) {
            colleagueList.add(colleague);
            colleague.setMediator(this);
        }
    }

    @Override
    public void relay(Colleague colleague) {
        for (Colleague obj : colleagueList) {
            if (colleague.equals(obj)) {
                obj.receive();
            }
        }
    }
}
